document.addEventListener('DOMContentLoaded', () => {
    const autoFormat = document.getElementById('auto-format');
    const themeSelect = document.getElementById('theme');
    const resetBtn = document.getElementById('reset');

    // 加载保存的设置
    chrome.storage.sync.get(['autoFormat', 'theme'], (result) => {
        autoFormat.checked = result.autoFormat !== false; // 默认开启
        themeSelect.value = result.theme || 'dark';
    });

    // 保存设置更改
    autoFormat.addEventListener('change', () => {
        chrome.storage.sync.set({ autoFormat: autoFormat.checked });
    });

    themeSelect.addEventListener('change', () => {
        chrome.storage.sync.set({ theme: themeSelect.value });
    });

    // 重置设置
    resetBtn.addEventListener('click', () => {
        autoFormat.checked = true;
        themeSelect.value = 'dark';
        chrome.storage.sync.set({
            autoFormat: true,
            theme: 'dark'
        });
    });
});